﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;

/// <summary>
/// DateUtil 的摘要描述
/// </summary>
public static class DateUtil
{
    
    /// <summary>
    /// 轉換成yyyy-MM-dd-00-00-00
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static DateTime ConvertToZeroHour(this DateTime dt) {
        //DateTime newDt = dt;
        String dt_str=dt.ToString("yyyy-MM-dd")+"-00-00-00";

        return DateTime.ParseExact(dt_str,"yyyy-MM-dd-HH-mm-ss",null);

    }
    /// <summary>
    /// 轉換成yyyy-MM-dd-23-59-59
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static DateTime ConvertToMaxHour(this DateTime dt)
    {
        //DateTime newDt = dt;
        String dt_str = dt.ToString("yyyy-MM-dd") + "-23-59-59";

        return DateTime.ParseExact(dt_str, "yyyy-MM-dd-HH-mm-ss", null);

    }

    /// <summary>
    /// 回傳民國年格式日期時間 100-02-14 08:00
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static string ConvertToROCDT(this DateTime dt)
    {
        TaiwanCalendar tc = new TaiwanCalendar();

        return tc.GetYear(dt) + "-" + dt.ToString("MM-dd HH:mm");
    }

    /// <summary>
    /// 回傳民國年格式日期 100-02-14
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static string ConvertToROC(this DateTime dt)
    {
        TaiwanCalendar tc = new TaiwanCalendar();

        return tc.GetYear(dt) + "-" + dt.ToString("MM-dd");
    }

    /// <summary>
    /// 將字串裡換行符號改成BR
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static string ConvertToBR(this string val)
    {
        val = val.Replace("\n", "<br/>");
        return val;
    }

    /// <summary>
    /// 將字串裡BR符號改成換行
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static string ConvertToNewLine(this string val)
    {
        val = val.Replace("<br/>", "\n");
        return val;
    }


}